cmake_minimum_required(VERSION 3.16)

project(NewFlow LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_PREFIX_PATH "D:/Qt/Qt6.8.1/6.8.1/msvc2022_64")

# 版本号
set(VERSION_MAJOR 2)
set(VERSION_MINOR 0)
set(VERSION_PATCH 1)

#------------------------------- 查找依赖 --------------------------------
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Charts PrintSupport)
qt_standard_project_setup()

#------------------------------- 源文件设置 --------------------------------
set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(SOURCE_MOUDLE_DIR ${SOURCE_DIR}/moudle)
set(SOURCE_CONTROL_DIR ${SOURCE_DIR}/control)
set(SOURCE_UI_DIR ${SOURCE_DIR}/ui)
set(SOURCE_LICENSE_DIR ${SOURCE_DIR}/license)
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(OPENSLL_INCLUDE_DIR "C:/OpenSSL-Win64/include")
set(VTK_INCLUDE_DIR "C:/Program Files (x86)/VTK/include/vtk-9.4")
include_directories(${VTK_INCLUDE_DIR} ${INCLUDE_DIR} ${OPENSLL_INCLUDE_DIR})
file(GLOB PROJECT_SOURCES 
    ${SOURCE_DIR}/main.cpp
    ${SOURCE_MOUDLE_DIR}/*.cpp
    ${SOURCE_CONTROL_DIR}/*.cpp
    ${SOURCE_UI_DIR}/*.cpp
    ${SOURCE_LICENSE_DIR}/*.cpp
)
file(GLOB INCLUDE_SOURCES 
    ${INCLUDE_DIR}/*.h
)
list(APPEND PROJECT_SOURCES ${INCLUDE_SOURCES})

#------------------------------- 链接库 --------------------------------
# 设置 VTK 库
set(VTK_LIB_PATH "C:/Program Files (x86)/VTK/lib")
set(VTK_LIBS
    vtksys-9.4 vtkImagingCore-9.4 vtkIOImage-9.4 vtkGUISupportQt-9.4 
    vtkCommonCore-9.4 vtkCommonDataModel-9.4 vtkCommonExecutionModel-9.4
    vtkFiltersCore-9.4 vtkFiltersGeneral-9.4 vtkFiltersGeometry-9.4 vtkFiltersModeling-9.4 vtkFiltersSources-9.4
    vtkRenderingCore-9.4 vtkRenderingAnnotation-9.4 vtkRenderingContext2D-9.4 vtkRenderingOpenGL2-9.4 vtkRenderingLOD-9.4
    vtkInteractionStyle-9.4 vtkInteractionWidgets-9.4 vtkInteractionImage-9.4
)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
    set(VTK_LIBS_DEBUG "")
    foreach(lib ${VTK_LIBS})
        list(APPEND VTK_LIBS_DEBUG "${lib}d")
    endforeach()
    set(VTK_LIBS ${VTK_LIBS_DEBUG})
endif()
foreach(vtk_lib ${VTK_LIBS})
    add_library(${vtk_lib} STATIC IMPORTED)
    set_target_properties(${vtk_lib} PROPERTIES IMPORTED_LOCATION "${VTK_LIB_PATH}/${vtk_lib}.lib")
endforeach()

# 设置 OpenSLL 库
set(OPENSSL_LIB_PATH "C:/OpenSSL-Win64/lib/VC/x64/MD")
set(OPENSSL_LIBS
    libcrypto libssl
)
foreach(openssl_lib ${OPENSSL_LIBS})
    add_library(${openssl_lib} STATIC IMPORTED)
    set_target_properties(${openssl_lib} PROPERTIES IMPORTED_LOCATION "${OPENSSL_LIB_PATH}/${openssl_lib}.lib")
endforeach()

#------------------------------- 翻译文件 --------------------------------
set(TRANSLATIONS
    "${PROJECT_SOURCE_DIR}/translations/zh_CN.ts"
)
find_program(LUPDATE_EXECUTABLE lupdate)
find_program(LRELEASE_EXECUTABLE lrelease)
foreach(_ts_file ${TRANSLATIONS})
    execute_process(COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_SOURCE_DIR} -ts ${_ts_file})
    execute_process(COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file})
endforeach()

#------------------------------- 资源文件 --------------------------------
# 资源文件
qt_add_resources(PROJECT_SOURCES resources/Resource.qrc)

# 设置应用程序图标路径
if (WIN32)
    set(APP_ICON_RESOURCE "${PROJECT_SOURCE_DIR}/resources/icon/EFlow.ico")  # 确保文件名正确
endif()

#------------------------------- 可执行文件 --------------------------------
add_executable(${PROJECT_NAME} WIN32 
    ${PROJECT_SOURCES} 
    ${APP_ICON_RESOURCE}
    "${PROJECT_SOURCE_DIR}/resources/NewFlow_icon.rc"  # 显式包含 .rc 文件
)

# 设置图标属性
if (WIN32)
    set_target_properties(${PROJECT_NAME}
        PROPERTIES
            WIN32_EXECUTABLE TRUE
            RC_ICONS ${APP_ICON_RESOURCE}
    )
endif()

#------------------------------- 链接库 --------------------------------
target_link_libraries(${PROJECT_NAME}
    PUBLIC
        Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Charts Qt6::PrintSupport
        ${OPENSSL_LIBS}
        ${VTK_LIBS}
)
